#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""

"""

__author__ = 'Lei Chen'

import codecs
import configparser
import os

# 默认配置文件
DIR = os.path.split(os.path.realpath(__file__))[0]
_DEFAULT_FILE = os.path.join(DIR, 'dubbo.ini')


class DubboConfigParser(object):

    def __init__(self, config_file=None):
        _file = config_file or _DEFAULT_FILE

        with open(_file, encoding='UTF-8') as fd:
            data = fd.read()
            if data[:3] == codecs.BOM_UTF8:
                data = data[3:]
                with codecs.openFile(_file, 'w') as file:
                    file.write(data)

        self.cf = configparser.RawConfigParser()
        self.cf.read(_file, encoding='UTF-8')

    def get(self, section, name):
        try:
            return self.cf.get(section, name)
        except Exception:
            return None

    def config(self):
        return Config(self, 'ZOOKEEPER')


class Config(object):

    def __init__(self, parser, system):
        self.system = system
        self.host = parser.get('ZOOKEEPER', 'host')
        self.timeout = parser.get('ZOOKEEPER', 'timeout')
        self.node = parser.get('ZOOKEEPER', 'node')


def main():
    pass


if __name__ == '__main__':
    main()
